package com.plum.admin.config.interceptor;

import com.plum.admin.config.properties.IgnoredUrlsProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * TODO
 *
 * @author 子丶沫
 * @version 1.0
 * @date 2021/9/28 10:02
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Autowired
    private LimiterInterceptor limiterInterceptor;
    @Autowired
    private LoginInterceptor loginInterceptor;
    @Autowired
    private IgnoredUrlsProperties ignoredUrlsProperties;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器
        InterceptorRegistration ir = registry.addInterceptor(limiterInterceptor);
        // 配置拦截的路径
        ir.addPathPatterns("/**");
        // 配置不拦截的路径 避免加载css也拦截（可根据实际情况放开限流配置或拦截路径）
        ir.excludePathPatterns(ignoredUrlsProperties.getLimitUrls());
    }
}
